package com.ali.gts.servlet.controller;

import com.ali.gts.servlet.service.ThreadLocalService;
import com.ali.gts.servlet.service.impl.ThreadLocalServiceImpl;
import com.ali.gts.servlet.util.JDBCUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 *  主要是通过这个Servlet 学习下ThreadLocal 来管理事务
 *
 */
public class ThreadLocalServlet extends BaseServlet{

    ThreadLocalService threadLocalService = new ThreadLocalServiceImpl();


    public void threadLocalTransaction(HttpServletRequest req, HttpServletResponse resp){

//        这里如果在Filter里面做了try-catch 后就不用trycatch了
//        try{
//            threadLocalService.threadLocalTransaction();
//            JDBCUtils.commitAndClose();
//        }catch (Exception e){
//            JDBCUtils.robackAndClose();
//        }

        threadLocalService.threadLocalTransaction();
    }


}
